<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Home\Statistics;
use App\Admin\Repositories\DayTime;
use App\Enums\CurrencyAssetEnum;
use App\Http\Controllers\Controller;
use App\Models\CensusModel;
use App\Models\CurrencyAsset;
use App\Models\JobpositionStatisticsModel;
use App\Models\JobPositionUpdateModel;
use App\Models\PlatformModel;
use App\Models\SignUpJobpositionModel;
use App\Models\User;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;
use Illuminate\Support\Facades\DB;

class CensusController extends Controller
{
    public function index(Content $content)
    {
        $id = request('id');

        $type = [];
        if ($id == 1) {
            $type['type'] = 'ios';
        }
        if ($id == 2) {
            $type['type'] = 'andr';
        }
        if ($id == 3) {
            $type['type'] = 'mini';
        }

        $top = [
            [
                'name' => '系统流量',
                'value' => CensusModel::distinct()->where($type)->count('type_unique'),
            ],
            [
                'name' => '职位标记',
                'value' => CensusModel::distinct()->where('url', 'api/v1/jobposition/detail')->where($type)->count('type_unique'),
            ],
            [
                'name' => '报名标记',
                'value' => CensusModel::distinct()->where('url', 'api/v1/jobposition/sign-up')->where($type)->count('type_unique'),
            ],
            [
                'name' => '注销用户',
                'value' => CensusModel::distinct()->where('url', 'api/v1/auth/unsubscribe')->where($type)->count('type_unique'),
            ],
        ];

        $platform = new PlatformModel;
        $list = $platform->get();

        $active = '';
        if (empty($id)) {
            $active = 'active';
        }

        $li = '<li><a href="/admin/census" class="' . $active . '">全部</a><a style="visibility: hidden;"><i class="feather icon-plus-square"></i></a></li>';

        foreach ($list as &$item) {
            $active_item = '';
            if ($id == $item->id) {
                $active_item = 'active';
            }
            $li .= '<li><a href="/admin/census?id=' . $item->id . '" class="' . $active_item . '">' . $item->name . '</a><a style="visibility: hidden;"><i class="feather icon-plus-square"></i></a></li>';
        }

        $hmtl = '<div class="grid-selector">
        <div class="wrap">
        <div class="select-label">分类</div>
        <div class="select-options">
                    <ul>' . $li . '</ul>
                </div>
            </div>  
        </div>';

        $body = function (Row $row) use ($top, $hmtl) {
            $row->column(12, $hmtl);
            $row->column(12, admin_view('admin.home', compact('top')));
        };

        return $content
            ->header('运营设置')
            ->description('统计分析')
            ->body($body);
    }
    public function statistics() {}
}
